home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9875 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  64 lines

  1. Path: news.infinet.com!cedwards
  2. From: cedwards@infinet.com (Chad Edwards)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using cin like sscanf()?
  5. Date: 4 Mar 1996 23:34:40 GMT
  6. Organization: InfiNet
  7. Message-ID: <4hfumg$np4@news1.infinet.com>
  8. References: <4gnudd$dd4@daily-planet.nodak.edu>
  9. NNTP-Posting-Host: 206.103.240.10
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Jeffro (ishaq@plains.nodak.edu) wrote:
  13. : greetings!  I've always wondered if this is possible.  Well, I'm sure
  14. : it's possible, but how is it done?  Say I input a string into string:
  15.  
  16. : char string[] = "This is a character string.";
  17. : char buffer[24];
  18.  
  19. : How can I tell cin to read from string instead of stdin so I can do
  20. : soemthing like this:
  21.  
  22. : //cin.read_from(string)
  23. : while (cin >> buffer) cout << buffer;    //Outputs string
  24. : //cin.read_from(stdin)
  25.  
  26. : This should be similar to:
  27.  
  28. : while (sscanf(string, "%s", &buffer)) cout << buffer;
  29.  
  30. : Any ideas?
  31. : Thanks!
  32. :     -jeff
  33. : --
  34. :  .,;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.
  35. :  - Jeff Ishaq ishaq@plains.nodak.edu               Computer Science major -
  36. :  - at North Dakota State University in Fargo, ND.  Drop me a line, eh?    -
  37. :  .,;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.;';.,.
  38. :  - better-than-average Phish songs:  Chalk Dust Torture, You Enjoy Myself,
  39. :  - David Bowie, Mound, Split Open and Melt, My Friend (has got a knife),
  40. :  - Fire Up The Ganga (live, of course), Contact
  41.  
  42. Assuming I understand what you want to do correctly:
  43.  
  44. #include <iostream.h>
  45.  
  46. void main()
  47. {
  48.   char stringOne[256];
  49.  
  50.   cout << "Enter a string: ";
  51.   cin.get (stringOne,256);
  52.   cout << stringOne: " << stringOne << end1;
  53.  
  54. }
  55.  
  56. --
  57.  
  58.  
  59. ______________________________________________________________________________
  60. A SIG? What the heck is a Sig? Something you smoke?
  61. http://www.infinet.com/~cedwards 
  62. ______________________________________________________________________________
  63.  
  64.